package NewTmas.Listeners;

import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

/**
 * Created by IntelliJ IDEA.
 * User: abhatnag
 * Date: 6/24/11
 * Time: 11:27 AM
 * To get the existing windows on the DesktopPane in the window menu
 */
public class WindowOpenListener implements MenuListener {
    JDesktopPane dtp;
    JInternalFrame[] frameSet;
    JMenu window;
    JMenuItem item;
    JMenuItem selectedItem;

    public WindowOpenListener(JMenu window, JDesktopPane dtp) {

        this.dtp=dtp;
        this.window = window;
    }

    public void menuSelected(MenuEvent e) {


        window.removeAll();
        frameSet=dtp.getAllFrames();

        for (final JInternalFrame internalFrame : frameSet)
        {
            item = new JMenuItem(internalFrame.getTitle());
            item.addActionListener(new WindowFocusListener(internalFrame));
            window.add(item);
        }
    }

    public void menuDeselected(MenuEvent e) {
    }

    public void menuCanceled(MenuEvent e) {
    }


}
